package com.scenic.rd_android.threerd.chart;

import com.google.gson.Gson;
import com.scenic.rd_android.BaseTestClass;
import com.scenic.rd_android.threerd.rxjava_retrofit.ServiceFactory;

import org.junit.Test;

import java.io.IOException;

import retrofit2.Converter;
import retrofit2.Response;
import retrofit2.http.Field;
import retrofit2.http.FormUrlEncoded;
import retrofit2.http.Headers;
import retrofit2.http.POST;
import rx.Observable;
import rx.functions.Action1;

/**
 * Created by scenic on 16/9/12.
 */
public class Network extends BaseTestClass {

    public interface EupmInterface {

        @ServiceFactory.BaseUrl
        String baseUrl = "http://121.40.213.101:83";


        @Headers({
                "channel_type:1",
                "device_id:00-26-C7-33-97-EE",
                "company_id:123",
                "timespan:1473664355270"
        })

        //channel_type=1&device_id=00-26-C7-33-97-EE&company_id=10000&timespan=11945223222
        @POST("ServiceHosting/interface/GetDatas")
        @FormUrlEncoded
        Observable<Bean> getData(@Field("code") String code);
//code=epnc-upm01001&Para1=1& para2=0
    }

    @Test
    public void test() throws InterruptedException {

        Bean bean = new Bean();
        bean.message = "testMessage";
        bean.result = "true";

        bean.datas = new Bean.IBean();
        bean.datas.monthPowerSum = "mouthPowerSum";
        log(new Gson().toJson(bean));

        EupmInterface eupmInterface = ServiceFactory.create(EupmInterface.class);
        Observable<Bean> value = eupmInterface.getData("epnc_upm_0101001");//epnc_upm_0101001

        value.subscribe(new Action1<Bean>() {
            @Override
            public void call(Bean bean) {
                log("---" + bean);
            }
        });


        /**
         *

          {
            “message”:"msg",
            "result":"true or false",
            "datas": {object}
          }



         */


    }

    public static class ConvertBean<T> implements Converter<Response,T> {


        @Override
        public T convert(Response value) throws IOException {
            return null;
        }
    }

    public static class Bean {


        String message;
        String result;

        IBean datas;

        Bean() {
            System.out.println("========================");
        }

        public static class IBean extends ConvertBean<IBean>{
            @Override
            public IBean convert(Response value) throws IOException {

                return super.convert(value);
            }

            public String monthPowerSum;

            public String monthPRateSum;

            public String timeSpan;

            public String powerSum;

            public String pRateSum;

            public String qSum;

            public String pSum;

            public String powerFactor;

            public String yDayPowerSum;

            public String yDayPRateSum;
        }

        @Override
        public String toString() {
            return "Bean{" +
                    "datas=" + datas +
                    ", message='" + message + '\'' +
                    ", result='" + result + '\'' +
                    '}';
        }
    }



}
